import {ActionType, PageContainer, ProTable} from '@ant-design/pro-components';
import {useAccess} from '@umijs/max';
import {cloneDeep} from "lodash";
import request from "@/utils/request";
import React, {useRef} from "react";

const AccessPage: React.FC = () => {
    const access = useAccess();
    console.log('useAccess', access);
    const actionRef = useRef<ActionType>();
    const columns: any = [
        {
            title: '桩编码',
            dataIndex: 'pileCode',
            key: 'pileCode',
        },
        {
            title: '标识符',
            dataIndex: 'fileIdentify',
            key: 'fileIdentify',
            search: false,
        },
        {
            title: 'iccId',
            dataIndex: 'iccId',
            key: 'iccId',
            search: false,
        },
        {
            title: '创建时间',
            dataIndex: 'createTime',
            key: 'createTime',
            search: false,
        },
        {
            title: '更新时间',
            dataIndex: 'updateTime',
            key: 'updateTime',
            search: false,
        },
    ]
    return (
        <PageContainer
            ghost
            header={{
                title: '',
            }}
        >
            <ProTable<API.UserInfo>
                headerTitle="桩列表"
                actionRef={actionRef}
                rowKey="id"
                pagination={{defaultPageSize: 10}}
                search={{
                    labelWidth: 120,
                }}
                request={async (params, sorter, filter) => {
                    // const { data, success } = await queryUserList({
                    //   ...params,
                    //   // FIXME: remove @ts-ignore
                    //   // @ts-ignore
                    //   sorter,
                    //   filter,
                    // });
                    // return {
                    //   data: data?.list || [],
                    //   success,
                    // };
                    const cloneParams = cloneDeep(params);
                    delete cloneParams.current;
                    const {data, code} = await request('/api1/new/device/pageList', {
                        params: {
                            ...cloneParams,
                            currentPage: params.current
                        }
                    });
                    console.log('data', data);
                    if (code && code === 200) {
                        return {
                            data: data?.records || [],
                            success: true,
                            total: data?.total
                        };
                    }
                }}
                columns={columns}
            />
        </PageContainer>
    );
};

export default AccessPage;
